package MyDP;

/**
 * 01矩阵中的最大正方形的面积
 */
public class Leetcode0221 {
    public int maximalSquare(char[][] matrix) {
        if(matrix == null || matrix.length <= 0 || matrix[0].length <= 0){
            return 0;
        }

        int[][] dp = new int[matrix.length][matrix[0].length];
        int maxx = 0;
        for(int i=0; i<matrix.length; i++){
            for(int j=0; j<matrix[0].length; j++){
                if(i==0 || j==0){
                    dp[i][j] = matrix[i][j] - '0';
                }else{
                    if(matrix[i][j] == '1'){
                        dp[i][j] = Math.min(Math.min(dp[i-1][j-1], dp[i][j-1]), dp[i-1][j]) + 1;
                    }
                }
                maxx = Math.max(maxx, dp[i][j] * dp[i][j]);
            }
        }
        return maxx;
    }
}
